/*
 *
 *  * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 *
 *
 */

package com.iwindplus.auth.server.api;

import com.iwindplus.auth.api.AuthorizationApi;
import com.iwindplus.boot.domain.vo.ResultVO;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 认证相关内部接口实现类.
 *
 * @author zengdegui
 * @since 2020/9/20
 */
@RestController
@RequestMapping
@Validated
@Slf4j
@RequiredArgsConstructor
public class AuthorizationApiImpl implements AuthorizationApi {

    private final OAuth2AuthorizationService authorizationService;

    @Override
    public ResultVO<Boolean> checkAccessToken(String accessToken) {
        final OAuth2Authorization data = this.authorizationService.findByToken(accessToken, OAuth2TokenType.ACCESS_TOKEN);
        return ResultVO.success(Objects.nonNull(data));
    }
}
